<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>下拉列移动选项</title>
    <script>
        function move(fromId,toId){
            // 获取起始下拉列与目标下拉列的节点
            let fromChild = document.getElementById(fromId);
            let toChild = document.getElementById(toId);

            // 将fromChild中被选中的选项移动到toChild中
            // for(let i = 0; i < fromChild.length; i++){
            for(let i = fromChild.length - 1; i >= 0; i--){
                // 取出当前遍历的选项
                let op = fromChild.options[i];
                // 判断当前选项是否被选中
                if(op.selected){
                    // 如果被选中,则移动到目标下拉列
                    toChild[toChild.length] = op;
                    toChild[toChild.length - 1].selected = false;
                }
            }
        }
        function moveAll(fromId,toId){
            // 获取起始下拉列与目标下拉列的节点
            let fromChild = document.getElementById(fromId);
            let toChild = document.getElementById(toId);

            // 将fromChild中被选中的选项移动到toChild中
            for(let i = fromChild.length - 1; i >= 0; i--){
                let op = fromChild.options[i];
                toChild[toChild.length] = op;
                toChild[toChild.length - 1].selected = false;
            }
        }
    </script>
</head>
<body>
<table>
    <tr>
        <td>
            <select id="s1" multiple="multiple" style="width: 100px;height: 150px;">
                <option value="1">admin</option>
                <option value="2">alice</option>
                <option value="3">tom</option>
                <option value="4">jack</option>
            </select>
        </td>
        <td>
            <input type="button" value="&nbsp;-->" onclick="move('s1','s2')"><br>
            <input type="button" value="->>" onclick="moveAll('s1','s2')"><br>
            <input type="button" value="<--&nbsp;" onclick="move('s2','s1')"><br>
            <input type="button" value="<<-" onclick="moveAll('s2','s1')"><br>
        </td>
        <td>
            <select id="s2" multiple="multiple" style="width: 100px;height: 150px;">

            </select>
        </td>
    </tr>
</table>
</body>
</html>